package com.juejin.www.controller;

import com.juejin.www.aspect.Perm;
import com.juejin.www.model.DTO.PageDTO;
import com.juejin.www.model.DTO.Result;
import com.juejin.www.model.VO.AuditVO;
import com.juejin.www.model.VO.NoticeVO;
import com.juejin.www.service.NoticeService;
import com.juejin.www.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Jacky
 */
@Slf4j
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @Perm(permission = "notice:read")
    @GetMapping
    public Result getNotices(@RequestParam Integer currentPage,@RequestParam Integer pageSize,@RequestHeader("token") String jwt){
        log.info("获取通知列表");
        Integer recipient = JwtUtils.getIdByJWT(jwt);
        PageDTO<NoticeVO> notices = noticeService.getNotices(currentPage,pageSize,recipient);
        return Result.success(notices);
    }

    @Perm(permission = "notice:read")
    @GetMapping("/{id}/{auditId}")
    public Result getAuditResult(@PathVariable Integer id,@PathVariable Integer auditId){
        log.info("获取{}号审核结果",auditId);
        AuditVO auditResult = noticeService.getAuditResult(id,auditId);
        return Result.success(auditResult);
    }

    @Perm(permission = "notice:read")
    @GetMapping("/{recipient}")
    public Result getIsNotReadCount(@PathVariable Integer recipient){
        log.info("获取{}用户未读信息数",recipient);
        Integer isNotReadCount = noticeService.getIsNotReadCount(recipient);
        return Result.success(isNotReadCount);
    }
}
